const mysql = require("../mysql");
function response(num) {
    return new Promise(async (resolve,reject) => {
        try {
            let sql = `select * FROM qq_account where is_login = 0 and is_failed = 0 limit 0,1;`
            console.log(sql)
            mysql(sql, function (error, results, fields) {
                if (error)throw error;
                console.log('查询成功',results);
                if(results.length>0){
                    mysql(`update qq_account set is_failed = 1 where id = ${results[0].id};`, function (error, results, fields) {})
                    resolve({data:results,result:'success'});
                }else{
                    reject({errorMsg:'无数据',result:'failure'})
                }
                
            });
        } catch (e) {
            logger.error(e.message)
            resolve({ result: "failure ", errorMsg: e.message, status: (e.response || {}).status })
        }
    })
}
module.exports = async num =>{
    let res = await response(num);
    return res;
}